<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>生产登记(点击登记)</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="/css/animate.css" rel="stylesheet">
    <link href="/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="/bootstraptable/bootstrap-table.css" rel="stylesheet">
</head>
<body>
<div style="color: #0e9aef;">您正在做的业务是：生产管理--内部生产管理--生产登记</div>
<div class="container" style="margin-top: 20px;">
    <div style="text-align: right">
        <button type="button" id="sub_btn" class="btn btn-default">提交</button>
        <button type="button" name="sub_btn" onclick="javascript:history.back()" class="btn btn-default">返回</button>
    </div>
    <div style="margin-top: 5px">
        <div class="panel panel-default">
            <h3 style="text-align: center;margin-top: 20px">生产登记单</h3>
        <div class="panel-body">
            <form class="form-horizontal" id="make_form">
                <div class="form-group">
                    <div class="col-md-6">
                        <label class="control-label col-md-4">派工单编号：</label>
                        <div class="col-md-8">
                            <input type="text" readonly style="border: none;background-color: white" class="form-control" name="manufactureId" id="manufactureId">
                        </div>
                    </div>
                    <div class="col-md-6">
                        <label class="control-label col-md-4">工序名称：</label>
                        <div class="col-md-8">
                            <input type="text" readonly style="border: none;background-color: white" class="form-control" name="procedureName" id="procedureName">
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-6">
                        <label class="control-label col-md-4">负责人：</label>
                        <div class="col-md-8">
                            <input type="text"  style="border: none;border-bottom: 1px solid black" class="form-control" name="procedureResponsiblePerson" id="procedureResponsiblePerson">
                        </div>
                    </div>
                    <div class="col-md-6">
                        <label class="control-label col-md-4">设计工时数：</label>
                        <div class="col-md-8">
                            <input type="text" readonly style="border: none;background-color: white" class="form-control" name="labourHourAmount" id="labourHourAmount">
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-6">
                        <label class="control-label col-md-4">已用工时数：</label>
                        <div class="col-md-8">
                            <input type="text" readonly style="border: none;background-color: white" class="form-control" name="realLabourHourAmount" id="realLabourHourAmount">
                        </div>
                    </div>
                    <div class="col-md-6">
                        <label class="control-label col-md-4">本次工时数：</label>
                        <div class="col-md-8">
                            <input type="text" id="thisHour" style="border: none;border-bottom: 1px solid black" class="form-control">
                        </div>
                    </div>
                </div>
                <table  style="margin-top: 20px;" class="table table-bordered table-striped" data-toggle="table" id="make_table">
                    <thead>
                    <tr>
                        <th data-field="detailsNumber">序号</th>
                        <th data-field="productName">物料名称</th>
                        <th data-field="productId">物料编号</th>
                        <th data-field="amount">设计数量</th>
                        <th data-field="realAmount">已使用数量</th>
                        <th data-field="thisCount" data-formatter="formatterText">本次数量</th>
                    </tr>
                    </thead>
                </table>
                <div class="form-group" style="margin-top: 10px">
                    <div class="col-md-6">
                        <label class="control-label col-md-4">登记人</label>
                        <div class="col-md-8">
                            <input type="text" style="border: none;border-bottom: 1px solid black" class="form-control" name="register" id="register">
                        </div>
                    </div>
                    <div class="col-md-6">
                        <label class="control-label col-md-4">登记时间</label>
                        <div class="col-md-8">
                            <input type="text"  readonly style="border: none;background-color: white" class="form-control" name="registerTime" id="registerTime">
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

    <div class="modal fade " id="make_modal">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span>&times;</span>
                    </button>
                    <div class="modal-title">
                        <h4>本道工序是否已生产完成</h4>
                    </div>
                </div>
                <div class="modal-body">
                    <div style="text-align: right">
                        <button type="button" id="continued_btn" class="btn btn-default btn-lg">未完成</button>
                        <button type="button" id="finish_btn" class="btn btn-default btn-lg">完成</button>
                        <button type="button" id="return_btn" class="btn btn-default btn-lg">返回</button>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>



<!-- 全局js -->
<script src="/js/jquery.min.js?v=2.1.4"></script>
<script src="/js/bootstrap.min.js?v=3.3.6"></script>
<script src="/js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="/js/plugins/layer/layer.min.js"></script>

<!-- 自定义js -->
<script src="/js/hAdmin.js?v=4.1.0"></script>
<script src="/js/currentTime.js"></script>

<!-- 第三方插件 -->
<script src="/js/plugins/pace/pace.min.js"></script>

<!--BootstrapTable-->
<script src="/bootstraptable/bootstrap-table.min.js"></script>
<script src="/bootstraptable/locale/bootstrap-table-zh-CN.min.js"></script>

<script>
    $(function () {
        let gxId = localStorage.getItem("gxId")
        let manId = localStorage.getItem("manId")
        $("#make_form #registerTime").val(add(fortime()))
        $.post("/manufacture/detail/getId", {"gxId": gxId}, function (res) {
            $("#make_form #manufactureId").val(manId)
            $("#make_form #procedureName").val(res.procedureName)
            $("#make_form #labourHourAmount").val(res.labourHourAmount)
            $("#make_form #realLabourHourAmount").val(res.realLabourHourAmount)

        })
        $.post("/manufacture/detail/getIdByDetails", {"gxId": gxId}, function (res) {
            for (let i = 0; i < res.length; i++) {
                $("#make_table").bootstrapTable("append", res[i])
            }
        })

        //设置模态框的属性
        $("#make_modal").modal({
            backdrop: false,
            keyboard: false,
            show: false
        })

        $("#sub_btn").click(function () {
            $("#make_modal").modal("show")
        })

        $("#make_modal #return_btn").click(function () {
            $("#make_modal").modal("hide")
        })

        //未完成
        $("#make_modal #continued_btn").click(function () {
            let data = $("#make_table").bootstrapTable("getData")
            let dto = {
                "manufactureId": $("#make_form #manufactureId").val(),
                "procedureName": $("#make_form #procedureName").val(),
                "thisHour": $("#make_form #thisHour").val(),
                "register": $("#make_form #register").val(),
                "registerTime": $("#make_form #registerTime").val(),
                "btnTxt": $("#make_modal #continued_btn").html(),
                "procedureResponsiblePerson": $("#make_form #procedureResponsiblePerson").val()
            }
            dto.details = data
            console.log("数据",dto)
            $.ajax({
                url: "/manufacture/procedure/addProductionRecords",
                type: "post",
                data: JSON.stringify(dto),
                contentType: "application/json",
                success: function (data) {
                    if (data) {
                        window.location = "production_registrationUI"
                    }
                }
            })
        })

        //完成
        $("#make_modal #finish_btn").click(function () {
            let data = $("#make_table").bootstrapTable("getData")
            console.log(data)
            let dto = {
                "manufactureId": $("#make_form #manufactureId").val(),
                "procedureName": $("#make_form #procedureName").val(),
                "thisHour": $("#make_form #thisHour").val(),
                "register": $("#make_form #register").val(),
                "registerTime": $("#make_form #registerTime").val(),
                "btnTxt": $("#make_modal #continued_btn").html(),
                "procedureResponsiblePerson": $("#make_form #procedureResponsiblePerson").val()
            }
            dto.details = data
            $.ajax({
                url: "/manufacture/procedure/addProductionRecords",
                type: "post",
                data: JSON.stringify(dto),
                contentType: "application/json",
                success: function (data) {
                    if (data) {
                        window.location = "production_registrationUI"
                    }
                }
            })
        })

        })

        function formatterText(value, row, index) {
            return `<input type="text" name="thisCount" onblur="changeAmount(this)" onchange="changeText(this)" >`
        }

        //"数量"文本框失去焦点的事件
        function changeAmount(param) {
            // 文本框的数量
            let val = $(param).val()
            // 获取文本框所在的行索引
            let index = $(param).parent("td").parent().index()

            // 获取物料明细表格的所有数据
            let data = $("#make_table").bootstrapTable("getData")
            // 修改对应对象的amount
            data[index].thisCount = parseInt(val)
        }

        function changeText(parm) {
            let num1 = $("#make_table tr").find("td:eq(3)").html()
            let num2 = $("#make_table tr").find("td:eq(4)").html()
            if (parseInt(num2) > parseInt(num1 - $(parm).val())) {
                alert("本次数量不能超过可用数量")
                return
            }
        }
</script>

</body>
</html>